<template>
	<div>
		<div style='margin:10px 0px'>
			<el-button-group>
				<el-button type='primary' @click='create' icon='el-icon-edit'>创建角色</el-button>
			</el-button-group>
		</div>
		<list ref='list' init show-selection>
    	<el-table-column slot='column' label='操作' fixed='right' align='center' width='220'>
				<template slot-scope='{row}'>
					<el-button  size='mini' type='primary'  @click='edit(row)'>修改</el-button>
					<el-button  size='mini' type='success'  @click='apply(row)'>授权</el-button>
					<el-button  size='mini' type='danger'  @click='del(row)'>删除</el-button>
				</template>
			</el-table-column>
  	</list>
		<authTree ref='authTree' @updated='reloadAuth'></authTree>
		<edit-dialog ref='editDialog' @updated='reload'></edit-dialog>
	</div>
</template>

<script>
import list from '@/components/sys/role/list'
import editDialog from '@/components/sys/role/editDialog'
import authTree from '@/components/admin/auth/authTree'

export default {
	components:{
		list,
		editDialog,
		authTree
	},
	data(){
		return {

		}
	},
	computed:{
		//表单是否是编辑状态
		isFormEdit(){
			return this.form.id!=null
		}
	},
	mounted(){

	},
	methods:{
		exportExcel(){
			this.$refs.list.exportExcel()
		},
		create(){
			this.$refs.editDialog.open().then(that=>{

			})
		},

		apply(row){
			this.$refs.authTree.initData(row);
			this.$refs.authTree.open()
		},

		edit(row){
			if(row.id==-1){
				this.$message.error('该角色为系统超级角色，禁止修改！');
				return false
			}
			row.action = 'gets';
			this.$refs.editDialog.initData(row);
			this.$refs.editDialog.open();
		},
		//删除
		del(row){
			this.$refs.list.del(row)
		},
		openSummaryListDialog(){
			this.$refs.summaryListDialog.open({ hasDelivery:1,toInvoice:1})
		},
		reloadAuth(){
			this.$refs.authTree.reload()
		},
		reload(){
			this.$refs.list.reload()
		},
		print({row}){
			this.$refs.printLabel.open().then(that=>{
				that.getData({ids:row.id})
			})
		},
		printBatch(){
			if(this.$refs.list.selectionList.length===0){
				this.$message.warning('未选择资产数据');
				return false
			}
			let ids = this.$refs.list.selectionList.map(d=>{
				return d.id
			})
			this.$refs.printLabel.open().then(that=>{
				that.getData({ids:ids.join(',')})
			})
		},
		copy({row}){
			this.$refs.editDialog.open().then(that=>{
				that.create().then(res=>{
					let copyData = this.$commonJs.obj.copyByKey(row,['model','company_id','supplier_name','buy_date','price','amount','sn','remarks'])
					that.assign(copyData).clearValidate()
				})
			})
		},
		test2(){
			this.$refs.list.$refs.tableList.clearSelection()
		}
	}
}
</script>
